home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue25 / clinic / LOCATEU.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-05-25  |  2.0 KB  |  86 lines

  1. unit LocateU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Grids, DBGrids, Db, DBTables;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Table1: TTable;
  12.     DataSource1: TDataSource;
  13.     DBGrid1: TDBGrid;
  14.     EdtCustNo: TEdit;
  15.     EdtCompany: TEdit;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Button1: TButton;
  19.     Table1CustNo: TFloatField;
  20.     Table1Company: TStringField;
  21.     Table1Addr1: TStringField;
  22.     Table1Addr2: TStringField;
  23.     Table1City: TStringField;
  24.     Table1State: TStringField;
  25.     Table1Zip: TStringField;
  26.     Table1Country: TStringField;
  27.     Table1Phone: TStringField;
  28.     Table1FAX: TStringField;
  29.     Table1TaxRate: TFloatField;
  30.     Table1Contact: TStringField;
  31.     Table1LastInvoiceDate: TDateTimeField;
  32.     EdtAddr1: TEdit;
  33.     EdtAddr2: TEdit;
  34.     Label3: TLabel;
  35.     Label4: TLabel;
  36.     procedure Button1Click(Sender: TObject);
  37.     procedure FormCreate(Sender: TObject);
  38.   private
  39.     { Private declarations }
  40.   public
  41.     Edits: array[0..3] of TEdit;
  42.   end;
  43.  
  44. var
  45.   Form1: TForm1;
  46.  
  47. implementation
  48.  
  49. {$R *.DFM}
  50.  
  51. procedure TForm1.Button1Click(Sender: TObject);
  52. var
  53.   KeyFields: String;
  54.   Values: Variant;
  55.   Loop, Count: Integer;
  56. begin
  57.   Values := VarArrayCreate([0, 0], varVariant);
  58.   Count := 0;
  59.   for Loop := 0 to 3 do
  60.   begin
  61.     if Edits[Loop].Text <> '' then
  62.     begin
  63.       if KeyFields <> '' then
  64.         AppendStr(KeyFields, ';');
  65.       AppendStr(KeyFields, Copy(Edits[Loop].Name, 4, 255));
  66.       VarArrayRedim(Values, Count);
  67.       Values[Count] := Edits[Loop].Text;
  68.       Inc(Count);
  69.     end;
  70.   end;
  71.   { NB: The only partialness is for the last field if it is a string }
  72.   if not Table1.Locate(KeyFields, Values,
  73.            [loPartialKey, loCaseInsensitive]) then
  74.     raise Exception.Create('Search values not found')
  75. end;
  76.  
  77. procedure TForm1.FormCreate(Sender: TObject);
  78. begin
  79.   Edits[0] := EdtCustNo;
  80.   Edits[1] := EdtCompany;
  81.   Edits[2] := EdtAddr1;
  82.   Edits[3] := EdtAddr2;
  83. end;
  84.  
  85. end.
  86.